package com.echoesnet.echoesshortvideo.views.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.echoesnet.echoesshortvideo.R;

import java.util.List;

public class SharesAdapter extends RecyclerView.Adapter<SharesAdapter.MyViewHolder>{
    private LayoutInflater inflater;
    private Context mContext;
    private List<String> mDatas;

    //创建构造参数
    public SharesAdapter(Context context , List<String> datas){
        this.mContext = context;
        this.mDatas = datas;
        inflater = LayoutInflater.from(context);
    }

    //创建ViewHolder
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_share_icon , parent , false);
        MyViewHolder viewHolder = new MyViewHolder(view);

        view.setOnClickListener(view1 -> {
            if(onItemClickListener!=null)
                onItemClickListener.onClick(view1, (String)view1.getTag(R.id.viewTagFirst));
        });

        return viewHolder;
    }

    //绑定ViewHolder
    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        String shareKey = mDatas.get(position);
        //为textview 赋值
        holder.tvChannelName.setText(shareKey);

        holder.rlBody.setTag(R.id.viewTagFirst, shareKey);

        switch (shareKey)
        {
            case "我的动态":

                break;
            case "微信好友":
                holder.ivIcon.setImageResource(R.drawable.ico_wechat);
                break;
            case "QQ好友":
                holder.ivIcon.setImageResource(R.drawable.ico_qq);
                break;
            case "朋友圈":
                holder.ivIcon.setImageResource(R.drawable.ico_friends);
                break;
            case "QQ空间":
                holder.ivIcon.setImageResource(R.drawable.ico_qzone);
                break;
            case "举报":
                holder.ivIcon.setImageResource(R.drawable.ico_report);
                break;
            case "存至相册":
                holder.ivIcon.setImageResource(R.drawable.ico_download);
                break;
            case "复制链接":
                holder.ivIcon.setImageResource(R.drawable.ico_link);
                break;
            default:
                holder.ivIcon.setImageResource(R.drawable.default_120px);
                break;
        }
    }


    @Override
    public int getItemCount() {
        //Log.i("TAG", "mDatas "+mDatas);

        return mDatas.size();

    }

    //新增item
    public void addData(int pos){
        mDatas.add("新增");
        notifyItemInserted(pos);
    }

    //移除item
    public void deleateData(int pos){
        mDatas.remove(pos);
        notifyItemRemoved(pos);
    }

    class MyViewHolder extends RecyclerView.ViewHolder{

        TextView tvChannelName;
        ImageView ivIcon;
        RelativeLayout rlBody;

        public MyViewHolder(View itemView) {
            super(itemView);

            ivIcon = itemView.findViewById(R.id.ivIcon);
            tvChannelName = itemView.findViewById(R.id.tvChannelName);
            rlBody = itemView.findViewById(R.id.rlBody);

        }
    }

    private ItemClickListener onItemClickListener;
    public void setOnItemClickListener(ItemClickListener l) {
        this.onItemClickListener = l;
    }

    public interface ItemClickListener{
        void onClick(View v, String tag);
    }
}


